<template>
    <div class="order">
        <div class="topBox">
            <div class="title">
                {{ $t('assemble.订单管理') }}
            </div>
        </div>


        <div class="contentBox">

            <div class="top_content">
                <div class="selectBox" @click="departmentShow = true" style="color: #000000;">
                    {{ department == '' ? $t('assemble.请选择') : department }}
                </div>
                <div class="btns" @click="handleShuaxin">
                    {{ $t('assemble.刷新') }}
                </div>
            </div>

            <div class="top_content" style="margin-top: 20px;">
                <div class="selectBox">
                    <div>
                        <input class="inputItem" type="text" v-model="searchvalue"
                            :placeholder="$t('assemble.请输入商品标题或订单号')">
                    </div>
                    <div class="minibtn" @click="handlegetOrderlist">
                        <img class="searchimg" src="../../static/imgs/search.png" alt="" srcset="">
                    </div>

                </div>
                <div class="btns" @click="handleExcel">
                    {{ $t('assemble.订单列表') }}
                </div>
            </div>

        </div>


        <div v-if="dataList.length > 0" class="ListBox">

            <div class="orderItem" v-for="(item, index) in dataList">
                <div class="orderTop">
                    <div class="order_Num">
                        {{ $t('assemble.订单编号') }}
                        {{ item.number }}
                    </div>
                    <div class="btns" @click="handleOrderDetail(item, item.id)">
                        {{ $t('assemble.订单详情') }}
                    </div>
                </div>
                <div class="heng"></div>

                <div class="productmessage">
                    <img class="productimg" :src="item.images" alt="">
                    <div class="right_Box">
                        <div class="name">{{ item.name }}</div>
                        <div class="value">{{ $t('assemble.单价') }}单价：￥{{ item.price }}</div>
                        <div class="value">{{ $t('assemble.数量') }}：{{ item.num }}</div>
                        <div class="value">Total：￥{{ item.total }}</div>
                    </div>
                </div>
                <div class="heng"></div>

                <div class="statusBox">
                    <div v-show="item.state == -1" style="color: #E00000;margin-right: 20px;">{{ $t('assemble.未通过审批') }}
                    </div>
                    <div v-show="item.state == 0" style="color: #0061D2;">{{ $t('assemble.待审批') }}</div>
                    <div v-show="item.state == 1" style="color: #0061D2;">{{ $t('assemble.审核通过') }}</div>
                    <div v-show="item.state == 2" style="color: #E00000;">{{ $t('assemble.生产中') }}</div>
                    <div v-show="item.state == 3" style="color: #E00000;">{{ $t('assemble.发货') }}</div>
                    <div v-show="item.state == 4" style="color: #E00000;">{{ $t('assemble.完成') }}</div>

                    <div v-if="item.state == -1" style="color: #E00000;cursor: pointer;" @click="gotoDetail(item, item.id)">
                        {{
                            $t('assemble.未通过原因') }}</div>
                    <div v-if="item.is_status" class="statusItem" @click="handleReorder(item)">
                        {{ $t('assemble.复购此单') }}
                    </div>
                </div>
            </div>
        </div>

        <div class="noData" v-if="dataList.length == 0" style="margin-top: 100px;width: 100%;text-align: center;">
            暂无订单
        </div>

        <div class="heights"></div>


        <!-- 部门 -->
        <van-popup v-model="departmentShow" position="bottom" :style="{ height: '40%' }">
            <van-picker class="custom-picker" :title="$t('assemble.请选择')" :cancel-button-text="$t('assemble.取消')"
                :confirm-button-text="$t('assemble.确定')" show-toolbar :columns="departmentlist"
                @confirm="onConfirdepartment" @cancel="departmentShow = false" />
        </van-popup>

        <Tabbar></Tabbar>
    </div>
</template>
<script>
import Tabbar from '@/components/tabbar/index.vue';
import { getcompanyuser, getOrderlist, getinfodata } from '../../utils/api'
export default {

    components: {
        Tabbar
    },
    data() {
        return {
            lang: 'zh',
            searchvalue: '',//搜索内容
            uid: '',//部门显示内容
            departmentShow: false,
            departmentlists: [],//部门列表
            departmentlist: [],
            department: "",//部门
            dataList: [],
            pageInfo: {
                page: 1,
                limit: 10,
                total: 0,
            },
        }
    },
    created() {
        this.$i18n.locale = localStorage.getItem('langtype')
        this.lang = localStorage.getItem('langtype')
        this.getcompanyuserdataList()
        this.handlegetOrderlist()

    },
    mounted() {
        // this.getyinsi()
    },
    methods: {
        //获取部门列表
        async getcompanyuserdataList() {
            let res = await getcompanyuser()
            if (res.code == 1) {
                console.log("部门列表", res)
                this.departmentlists = res.data
                this.departmentlists.forEach((item, index) => {
                    this.departmentlist.push(item.nickname)
                })
                this.department = this.departmentlists[this.departmentlists.length - 1].nickname
                this.uid = this.departmentlists[this.departmentlists.length - 1].id
            }
            // if (res.code == 401) {
            //     this.$router.push({ path: '/login' })
            // }
        },
        //获取订单列表
        async handlegetOrderlist() {
            let data = {
                uid: this.uid,
                keyword: this.searchvalue,
                page: this.pageInfo.page,
                limit: this.pageInfo.limit
            }
            let res = await getOrderlist(data)
            this.dataList = res.data.list

        },
        onConfirdepartment(value, index) {
            this.department = value
            this.uid = this.departmentlists[index].id
            this.handlegetOrderlist()
            this.departmentShow = false
        },

        handleShuaxin() {
            this.searchvalue = ''
            this.uid = ''
            this.getcompanyuserdataList()
            this.handlegetOrderlist()
        },

        //复购
        async handleReorder(item) {
            let res = await getinfodata({
                id: item.id
            })
            localStorage.setItem('ReorderData', JSON.stringify(res.data))
            let id = res.data.product_id
            this.$router.push({ path: '/pages/home/detail', query: { id } })
        },

        handleExcel() {
            this.$router.push({ path: '/pages/order/orderList' })
        },

        handleOrderDetail(item, id) {
            localStorage.setItem("refusal", item.remark == null ? false : item.remark)
            this.$router.push({ path: '/pages/order/orderDetail', query: { id } })
        }

    },

}
</script>

<style scoped lang="scss">
.order {
    width: 100%;
    min-height: 100vh;
    background-color: #F8F8F8;
}

@media screen and (max-width: 750px) {
    .topBox {
        width: 100%;
        height: 44px;
        // padding: 10px 15px;
        padding-top: 10px;
        position: relative;
        font-family: PingFang SC, PingFang SC;
        font-weight: 600;
        font-size: 16px;
        color: #333333;
        line-height: 19px;
        text-align: left;
        font-style: normal;
        text-transform: none;
        background-color: #ffffff;

        .title {
            width: 100%;
            text-align: center;
        }
    }

    .contentBox {
        width: 100%;
        padding: 15px;
        box-sizing: border-box;
        background-color: #ffffff;

        .top_content {
            display: flex;
            align-items: center;
            justify-content: space-between;


            .selectBox {
                width: 259px;
                height: 40px;
                border-radius: 10px 10px 10px 10px;
                border: 1px solid #EDEDED;
                font-family: PingFang SC, PingFang SC;
                font-weight: 400;
                font-size: 14px;
                color: #B1B1B1;
                line-height: 40px;
                text-align: left;
                font-style: normal;
                text-transform: none;
                // padding-left: 10px;
                box-sizing: border-box;
                display: flex;
                justify-content: space-between;

                .inputItem {
                    outline: none;
                    border: none;
                    height: 30px;
                    border-radius: 20px;

                }

                .minibtn {
                    width: 50px;
                    height: 40px;
                    background: linear-gradient(315deg, #E00000 0%, #FF2424 100%);
                    border-radius: 10px 10px 10px 10px;
                    display: flex;
                    align-items: center;
                    justify-content: center;

                    .searchimg {
                        width: 20px;
                        height: 20px;
                    }
                }
            }

            .btns {
                width: 104px;
                height: 38px;
                background: linear-gradient(315deg, #E00000 0%, #FF2424 100%);
                border-radius: 10px 10px 10px 10px;
                font-family: PingFang SC, PingFang SC;
                font-weight: 400;
                font-size: 16px;
                color: #FFFFFF;
                line-height: 38px;
                text-align: center;
                font-style: normal;
                text-transform: none;
            }
        }

    }


    .ListBox {
        .orderItem {
            width: 100%;
            // height: 227px;
            background: #FFFFFF;
            padding: 15px;
            box-sizing: border-box;
            margin-top: 10px;

            .orderTop {
                display: flex;
                align-items: center;
                justify-content: space-between;


                .order_Num {
                    font-family: PingFang SC, PingFang SC;
                    font-weight: 400;
                    font-size: 14px;
                    color: #333333;
                    line-height: 16px;
                    text-align: left;
                    font-style: normal;
                    text-transform: none;
                }

                .btns {
                    width: 104px;
                    height: 38px;
                    background: linear-gradient(315deg, #E00000 0%, #FF2424 100%);
                    border-radius: 10px 10px 10px 10px;
                    font-family: PingFang SC, PingFang SC;
                    font-weight: 400;
                    font-size: 16px;
                    color: #FFFFFF;
                    line-height: 38px;
                    text-align: center;
                    font-style: normal;
                    text-transform: none;
                }
            }

            .heng {
                width: 345px;
                height: 1px;
                background-color: #EDEDED;
                margin: 15px auto;
            }

            .productmessage {
                height: 100px;
                display: flex;
                align-items: center;

                .productimg {
                    width: 100px;
                }

                .right_Box {
                    height: 100px;
                    margin-left: 10px;
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;

                    .name {
                        font-family: PingFang SC, PingFang SC;
                        font-weight: 400;
                        font-size: 14px;
                        color: #333333;
                        line-height: 16px;
                        text-align: justified;
                        font-style: normal;
                        text-transform: none;
                    }

                    .value {
                        font-family: PingFang SC, PingFang SC;
                        font-weight: 400;
                        font-size: 12px;
                        color: #666666;
                        line-height: 14px;
                        text-align: left;
                        font-style: normal;
                        text-transform: none;
                    }
                }
            }

            .statusBox {
                display: flex;
                font-family: PingFang SC, PingFang SC;
                font-weight: 500;
                font-size: 16px;
                color: #009E42;
                line-height: 19px;
                text-align: right;
                font-style: normal;
                text-transform: none;
                justify-content: end;

                .statusItem {
                    margin-left: 20px;
                }
            }

        }
    }

    .heights {
        height: 100px;
    }

}

@media screen and (min-width: 751px) and (max-width: 1300px) {
    .noData {
        font-size: 23px;
    }

    .topBox {
        width: 100%;
        height: 88px;
        // padding: 10px 15px;
        padding-top: 20px;
        position: relative;
        font-family: PingFang SC, PingFang SC;
        font-weight: 600;
        font-size: 25px;
        color: #333333;
        line-height: 19px;
        text-align: left;
        font-style: normal;
        text-transform: none;
        display: flex;
        align-items: center;
        background-color: #ffffff;


        .title {
            width: 100%;
            text-align: center;

        }
    }

    .contentBox {
        width: 100%;
        padding: 20px 60px;
        box-sizing: border-box;
        background-color: #ffffff;

        .top_content {
            display: flex;
            align-items: center;
            justify-content: space-between;


            .selectBox {
                width: 70%;
                height: 80px;
                border-radius: 10px 10px 10px 10px;
                border: 2px solid #EDEDED;
                font-family: PingFang SC, PingFang SC;
                font-weight: 400;
                font-size: 24px;
                color: #B1B1B1;
                line-height: 80px;
                text-align: left;
                font-style: normal;
                text-transform: none;
                padding-left: 10px;
                box-sizing: border-box;
                display: flex;
                justify-content: space-between;

                .inputItem {
                    outline: none;
                    border: none;
                    height: 70px;

                }

                .minibtn {
                    width: 100px;
                    height: 80px;
                    background: linear-gradient(315deg, #E00000 0%, #FF2424 100%);
                    border-radius: 10px 10px 10px 10px;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                }
            }

            .btns {
                width: 208px;
                height: 76px;
                background: linear-gradient(315deg, #E00000 0%, #FF2424 100%);
                border-radius: 10px 10px 10px 10px;
                font-family: PingFang SC, PingFang SC;
                font-weight: 400;
                font-size: 24px;
                color: #FFFFFF;
                line-height: 76px;
                text-align: center;
                font-style: normal;
                text-transform: none;
            }
        }

    }


    .ListBox {
        .orderItem {
            width: 100%;
            // height: 227px;
            background: #FFFFFF;
            padding: 40px;
            box-sizing: border-box;
            margin-top: 30px;

            .orderTop {
                display: flex;
                align-items: center;
                justify-content: space-between;


                .order_Num {
                    font-family: PingFang SC, PingFang SC;
                    font-weight: 400;
                    font-size: 24px;
                    color: #333333;
                    line-height: 24px;
                    text-align: left;
                    font-style: normal;
                    text-transform: none;
                }

                .btns {
                    width: 190px;
                    height: 70px;
                    background: linear-gradient(315deg, #E00000 0%, #FF2424 100%);
                    border-radius: 10px 10px 10px 10px;
                    font-family: PingFang SC, PingFang SC;
                    font-weight: 400;
                    font-size: 24px;
                    color: #FFFFFF;
                    line-height: 70px;
                    text-align: center;
                    font-style: normal;
                    text-transform: none;
                }
            }

            .heng {
                width: 90%;
                height: 1.5px;
                background-color: #EDEDED;
                margin: 15px auto;
            }

            .productmessage {
                height: 250px;
                display: flex;
                align-items: center;

                .productimg {
                    width: 250px;
                }

                .right_Box {
                    height: 250px;
                    margin-left: 10px;
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;

                    .name {
                        font-family: PingFang SC, PingFang SC;
                        font-weight: 400;
                        font-size: 24px;
                        color: #333333;
                        line-height: 24px;
                        text-align: justified;
                        font-style: normal;
                        text-transform: none;
                    }

                    .value {
                        font-family: PingFang SC, PingFang SC;
                        font-weight: 400;
                        font-size: 20px;
                        color: #666666;
                        line-height: 14px;
                        text-align: left;
                        font-style: normal;
                        text-transform: none;
                    }
                }
            }

            .statusBox {
                margin-top: 30px;
                font-family: PingFang SC, PingFang SC;
                font-weight: 500;
                font-size: 24px;
                color: #009E42;
                line-height: 19px;
                display: flex;
                justify-content: end;

                .statusItem {
                    margin-left: 20px;
                }
            }

        }
    }

    .heights {
        height: 200px;
    }


}
</style>